<?php
/**
 * 搜索处理类
 * @author Ice <iceinto@mallog.com.cn>
 */
class SearchAction extends BaseAction
{
    public function index()
    {
        $name = trim($this->_get('keyword',''));
        $BrandModel = D('Brand');
        $brand = $BrandModel->getOneByEname($name);
        //TODO 添加缓存处理
        if (!empty($brand)) {
            //品牌详细信息 获取图片
            $image = $BrandModel->getByIdDetailAndImage($brand['id']);
            $brand['image_url'] = $image['image_url'];
            //获取关注
            $brand['att_count'] = D('BrandAttention')->getAttCount($brand['id']);
            $BrandModel->attCheckCount($brand['id'], $brand['att_count']);
            //获取展示图
            $brand['slide'] = D('Slide')->getBrandOne($brand['id']);
            //获取品牌柜台
            $FloorBrandModel = D('FloorBrand');
            $BrandNewsModel = D('BrandNews');
            $map = array();
            $map['m_brand.id'] = $brand['id'];
            $floorBrands = $FloorBrandModel->getSearchBrand($map);
            foreach ($floorBrands as $key => $b) {
                $floorBrands[$key]['dis'] = $BrandNewsModel->getOneNew($b['mid'], $b['fid'], $b['bid']);
            }
            //排序
            $fdis = array();
            $fnodis = array();
            foreach ($floorBrands as $key => $b) {
                if (empty($b['dis'])) {
                    $fdis[] = $b;
                } else {
                    $fnodis[] = $b;
                }
            }
            unset($floorBrands);
            //排序后进行合并数组
            $floorBrands = array_merge($fnodis, $fdis);
            $this->assign('brand', $brand);
            $this->assign('fb', $floorBrands);
            $this->assign('web_title', $brand['name']);
        } else {
            $this->errorLang('_SEARCH_BRAND_NO_');
        }
        $this->display();
    }
}

?>